from enum import Enum

from Lib.zcm.exception.errorcode import ErrorCode
from Lib.zcm.localization.message import Msg


class ErrorType(Enum):
    """
    定义异常类型
    """

    '''
    框架报错异常
    '''
    ZCM_LIB = 'ERROR_TYPE_LIB'

    '''
    业务报错异常， 明确的是业务有问题导致的异常
    '''
    BUSINESS = 'ERROR_TYPE_BUSINESS'

    # Add by james at 20200813
    # get the error type from error code
    @classmethod
    def get_type_from_code(cls, code: ErrorCode):
        # 参数code没值
        if code and code.value[0] == '5':
            return ErrorType.BUSINESS
        else:
            return ErrorType.ZCM_LIB

    def __str__(self):
        return Msg.get_error_type(self.value)


if __name__ == '__main__':
    print(ErrorType.get_type_from_code(ErrorCode.BUSINESS_FLOW_ERROR))
